<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<%String path = request.getContextPath() ;%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<jsp:include page="../../import.jsp" flush="true" />
<jsp:include page="../../ass/assParking/assParkCommon.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div>
<div id="pageInTab" class="pageInTab">
	<!-- 页签1-->
	<div tabid="tabA" title="档案管理" lselected="true">
		<div class="searchArea">
			<!-- 搜索表单开始 -->
			<form id="searchBar">
				<div class="fieldset1 clearFix">
					<div class="FXBR">
						<div class="fieldBox">
							<div class="label">客户名称</div>
							<div class="field">
								<input type="text" id="cstNm" name="cstNm" class="ui-textbox" ligerui="width: 160" value="">
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">合同编号</div>
							<div class="field">
								<input type="text" id="contNo" name="contNo" class="ui-textbox" ligerui="width: 160" value="">
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">归档状态</div>
							<div class="field">
								<select id="archiveState"  name="archiveState"  ligerui="width: 160">
									<option value="">请选择</option>
									<c:forEach items="${archiveStateList}" var="item">
										<option value="${item.key}">${item.value}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">业务类型</div>
							<div class="field">
								<select id="bizTypCd"  name="bizTypCd"  ligerui="width: 160">
									<option value="">请选择</option>
									<c:forEach items="${bizTypeList}" var="item">
										<option value="${item.key}">${item.value}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">支付表状态</div>
							<div class="field">
								<select id="prdStsCd"  name="prdStsCd"  ligerui="width: 160">
									<option value="">请选择</option>
									<c:forEach items="${prdStsCdList}" var="item">
										<option value="${item.key}">${item.value}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						
						<div class="fieldBox">
							<div class="label">支付表号</div>
							<div class="field">
								<input type="text" id="paySchNo" name="paySchNo" class="ui-textbox" ligerui="width: 160" value="">
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">处置状态</div>
							<div class="field">
								<select name="dealStsCd" id="dealStsCd" ligerui="width: 160">
									<option value="">请选择</option>
									<c:forEach items="${dealStsList }" var="deal">
										<option value="${deal.key }">${deal.value }</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">拖车状态</div>
							<div class="field">
								<select name="backStsCd" id="backStsCd" ligerui="width: 160">
									<option value="" seleted>请选择</option>
									<c:forEach items="${backStsList }" var="back">
										<option value="${back.key }">${back.value }</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">拖回时间</div>
							<div class="field">
								<input type="text" id="beginBackDate" name="beginBackDate" class="ui-datepicker" ligerui="width: 120" value="">
								至
								<input type="text" id="endBackDate" name="endBackDate" class="ui-datepicker" ligerui="width: 120" value="">
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">拖回天数</div>
							<div class="field">
								<input type="text" id="minBackDay" name="minBackDay" class="ui-textbox" ligerui="width: 100" value="">
								至
								<input type="text" id="maxBackDay" name="maxBackDay" class="ui-textbox" ligerui="width: 100" value="">
							</div>
						</div>
					</div>
					<!-- 隐藏当前选中的拖车主表ID和明细表ID信息 -->
					<div class="fieldBox" style="display:none;">
						<div class="field">
							<input name="tcMasterId" id="tcMasterId" type="text" class="ui-textbox" value="${tcMasterId}">
							<input name="tcDetailId" id="tcDetailId" type="text" class="ui-textbox" value="${tcDetailId}">
						</div>
					</div>
					
					<div class="clearFix"></div>
					
					<!-- 表单按钮 -->
					<div class="btnsBox formBtns notRight">
						<span id="searchBtn" class="sq-button-round">查询</span>
						<span id="clearBtn" class="sq-button-round">清空</span>
						<input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
						<span id="dealCarBtn" class="sq-button-round" onclick="dealCar();">设备处置</span>
						<span id="downBtn" class="sq-button-round" onclick="downloadBtnEvent();">导出Excel</span>
		            </div>
		            <!-- 逾期提醒 -->
					<div class="disp_right">
						<span>
							<font color="red"><i class="ico_flasher"></i>拖回天数已经60天</font>
						</span>
		            </div>
				</div>
			</form>
			<!-- 搜索表单结束 -->
		</div>
		<!-- 列表显示块 -->
		<div id="ligergrid1" class="sq-grid"></div>
	</div>
	<!-- 页签2-->
	<div id="tabBId"  tabid="tabB"  style="dis"  title="流程跟踪"  >
		<iframe  id="tabB"  name="tabB"  frameborder="0"></iframe>
	</div>
</div>
</div>
</div>
<script type="text/javascript">
	var pageInApp={
		flag:false //tab页验证关闭
	};//to下一级子窗口 接口
	var pageInTab=null;//页签
	var loadedTabs=[];//页签
	var grid = null;
	$(function () {
	    initForm();//初始化表单
	    initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
	    initTab();//初始化页签
	    searchBtnEvent();//查询按钮事件
	    clearBtnEvent();//清空按钮事件
	});
	
	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
		var data = form.getData();
		return data;
	}
	
	//初始化列表
	function initGrid(){
		$("#ligergrid1").ligerGrid({
			url:'<%=path%>/warrant/warrantfilemanage/initList.do',
			method:'get',
			parms:getSearchParams(),
			columns:[
				{ display: '<span class="sqiconfont sqicon-tishi c_sqYellow gridTip" title="拖车提醒"></span>', 
					name: '', minWidth: 30 , align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = '';
						if(rowdata.backDays>=60){//拖车提醒
							h = '<i class="ico_flasher"></i>';
						}
						return h;
					}},
					{
						display:'操作',
						isSort:false,
						width:100,
						align:'center',
						render:function (rowdata, rowindex, value){
							var h="";
							if(rowdata.payStatus == "正常"){
				            	h+='<a class="sq-button-hasicon" href="javascript:warrantFileManageApply(';
				                h+="'"+rowdata.paySchId+"'";
				                h+=",'"+rowdata.paySchNo+"'";
				                h+=",'"+rowdata.prjPrdDtlId+"'";
				                h+=",'"+rowdata.prjId+"'";
				                h+=",'"+rowdata.businessType+"'";
				                h+=",'"+rowdata.prjTypCd+"'";
				                h+=",'"+rowdata.prjNm+"'";
				                h+=",'"+rowdata.orgName+"'";
				                h+=",'"+rowdata.cstId+"'";
				                h+=",'"+rowdata.cstNm+"'";
				                h+=")\"><i class='sqBtnIco_4'></i>归档申请</a>";
							}else{
			                	h+='<font class="sq-button-hasicon" color="c9c9c9"><i class="sqBtnIco_4"></i>归档申请2</font>';
			                }
							
							return h;
						}
					},
				{ display: '合同编号', name: 'contNo', minWidth: 180 , align:'center', enabledSort:true},
				{ display: '支付表号', name: 'paySchNo', minWidth: 180 , align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = '';
						h='<a href="javascript:payDetail(';
                        h+="'"+rowdata.prjPrdDtlId+"',"; //项目产品明细信息表ID
                        h+="'"+rowdata.paySchId+"',"; //支付表ID
                        h+="'"+rowdata.prjPrdId+"',"; //项目产品基础信息表ID
                        h+="'"+rowdata.prjId+"'"; //项目基础信息表ID
						h+=')">'+value+'</a>';
						return h;
					}},
				{ display: '归档状态', name: 'archiveState', width: 120 , enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = '';
						h='<a href="javascript:payDetail(';
                        h+="'"+rowdata.prjPrdDtlId+"',"; //项目产品明细信息表ID
                        h+="'"+rowdata.paySchId+"',"; //支付表ID
                        h+="'"+rowdata.prjPrdId+"',"; //项目产品基础信息表ID
                        h+="'"+rowdata.prjId+"'"; //项目基础信息表ID
						h+=')">'+value+'</a>';
						return rowdata.archiveState;
					}},
				{ display: '权证责任人', name: 'managerNm', width: 120 , enabledSort:true},
				{ display: '客户名称', name: 'cstNm', width: 120 , enabledSort:true},
				{ display: '逾期天数', name: 'overdueDay', width: 80 , enabledSort:true},
				{ display: '逾期租金(元)', name: 'overdueAmt', width: 100, align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = 0;
		                h = rowdata.overdueAmt / 100;
						return h;
					}},
				{ display: '罚息金额(元)', name: 'penaltyAmt', width: 100, align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = 0;
		                h = rowdata.penaltyAmt / 100;
						return h;
					}},
				{ display: '应付款总金额(元)', name: 'payAmt', width: 100, align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = 0;
		                h = rowdata.payAmt / 100;
						return h;
					}},
				{ display: '拖车状态', name: 'backStsCd', width: 80, align:'center', enabledSort:true},
				{ display: '拖回时间', name: 'actBackDt', width: 100, align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = renderDate1(rowdata.actBackDt);
						return h;
					}},
				{ display: '托回天数', name: 'backDays', width: 100, align:'center', enabledSort:true},
				{ display: '预计拖车费用(元)', name: 'backAmt', width: 100, align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = 0;
		                h = rowdata.backAmt / 100;
						return h;
					}},
				{ display: '实际拖车费用(元)', name: 'actBackAmt', width: 100, align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = 0;
		                h = rowdata.actPayAmt / 100;
						return h;
					}},
				{ display: '处置状态', name: 'dealStsCd', width: 100, align:'center', enabledSort:true},
				{ display: '保底价款(元)', name: 'baseAmt', width: 100, align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = 0;
		                h = rowdata.baseAmt / 100;
						return h;
					}}
				
			],
			pageSize:10,
			root:'rows',
			record:'total',
			hideLoadButton:false,
			width:'100%',
			height:'100%',
			heightDiff:-2,
			checkbox:true,//列表是否有选择框
			rownumbers:true,//列表是否有行号
			//选择行事件
			onSelectRow: function(rowdata, rowid, rowobj){
				//设置当前选择的拖车主表ID和明细表ID值
				$("#tcDetailId").val(rowdata.id);
				$("#tcMasterId").val(rowdata.masterId);
			},
			//取消选择行事件
			onUnSelectRow : function(rowdata, rowid, rowobj){
				//清空当前选择的拖车主表ID和明细表ID值
				$("#tcDetailId").val('');
				$("#tcMasterId").val('');
			}
		});
		grid = liger.get("ligergrid1");
		grid.setHeight(100);
		//grid.options.isSingleCheck = true;//列表是否为单选
	}
	
	//发起申请
	function warrantFileManageApply(paySchId,paySchNo,prjPrdDtlId,prjId,businessType,prjTypCd,prjNm,orgName,cstId,cstNm){
		//回调刷新列表
		var param = '<%=path%>/warrant/warrantfilemanage/toApplyPage.do?paySchId=' + paySchId + '&&paySchNo=' + paySchNo +'&&prjPrdDtlId='+prjPrdDtlId+'&&prjId='+prjId+'&&businessType='+businessType;
		param += '&&prjTypCd='+prjTypCd+'&&prjNm='+prjNm+'&&orgName='+orgName+'&&cstId='+cstId+'&&cstNm='+cstNm;
		
		Add_navTab('warrantFileManage'+paySchId,'归档申请',param, function () {
			grid.reload();
		});
	}
	
	//初始化Tab页签
	function initTab(){
		pageInTab = $("#pageInTab").ligerTab({
			height: 'auto',
			contextmenu: false,
			minIframeHeight: GET_minIframeHeight(),
			/* onBeforeSelectTabItem: function (tabid) {
				//获取客户ID供其它页面使用
				var _cId = $("#cId").val();
				if(tabid!="tabA" && !_cId){
					if(pageInApp.flag){
						$.ligerDialog.SQalert({content: LogUtils.LOG_CUST_CONFIRM_HERE_HAS_INFO, SQ_type: "warning"});
						return false;
					}
				}
			}, */
			onAfterSelectTabItem: function(tabid) {
				//if (loadedTabs.indexOf(tabid)<0) {//只加载一次
					//获取拖车主表ID和明细表ID供其它页面使用
					var tcDetailId = $("#tcDetailId").val();
					var tcMasterId = $("#tcMasterId").val();
					if(tabid!="tabA"){
						if(!tcDetailId || !tcMasterId){
							$.ligerDialog.SQalert({content: "请选择一条信息！", SQ_type: "warning"});
							return false; //验证不通过，不执行以下代码
						}
					}
					//loadedTabs.push(tabid);
					switch (tabid){
						case "tabB":							
							pageInTab.setTabItemSrc(tabid, "<%=path%>/ass/assTrailCarM/toFlowPage.do?tcMasterId="+tcMasterId+"&tcDetailId="+tcDetailId);
							break;
					}
				//};
				SetIframe_height();
			}
		});
		//设置页签
		$.extend(true, pageInApp, {
			pageInTab: pageInTab
		});
	};
	
	//清空按钮事件
	function clearBtnEvent(){
		$("#clearBtn").click(function(event) {
			$("#resetBtn").click();  //重置 input-text
			var form = liger.get("searchBar");
			form.setData({  //重置select等特殊表单
				"dealStsCd":"",
				"backStsCd":""
			});
		});
	}
	
	//查询按钮事件
	function searchBtnEvent(){
		$("#searchBtn").click(function(event) {
			var form = new liger.get("searchBar");
			var data = form.getData();
			//alert(JSON.stringify(data));
			for (name in data){
				grid.setParm(name,data[name]);
			};
			grid.reload();
		});
	}
	
	//查看支付表详情
	function payDetail(prjPrdDtlId,id,prjPrdId,prjId){
		var editFlag = true;
		Add_navTab('tab_prj_quat_prps'+id,'查看支付表','<%=path%>/project/prjprdpayschm/toAddPage.do?prjId='+prjId+'&&id='+id+'&&prjPrdDtlId='+prjPrdDtlId+'&&prjPrdId='+prjPrdId+'&&detailFlag='+editFlag);
	}
	
	//拖车申请
	function trailCarApply(paySchId,paySchNo){
		Add_navTab('trailCar'+paySchId,'拖车申请','<%=path%>/ass/assTrailCarD/toApplyPage.do?paySchId='+paySchId+'&&paySchNo='+paySchNo);
	}
	
	//设备处置
	function dealCar(){
		var selectedRows = grid.getSelectedRows();
        if (selectedRows.length != 1) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
            return;
        }
        var flowDialog = $.ligerDialog.SQopen({
            url: '<%=path%>/ass/assTrailCarM/toDealSelectPage.do',
            isDrag: true,   //是否拖动
            width: 280,     //宽度
            height: 200,   //高度，默认自适应 
            left: 200,     //位置left
            top: 130,      //位置top
            title : '请选择设备处置方案',
            onClose: function () {
            	var json = flowDialog._DATA;
            	var dealStsCd = selectedRows[0].dealStsCd;//处置状态
            	var backStsCd = selectedRows[0].backStsCd;//拖车状态
            	console.log(json);
            	if(!json || backStsCd!="已拖回" || dealStsCd=="优车处置不通过" || (dealStsCd!="未处置" && dealStsCd.indexOf("不通过") < 0)){
            		if(backStsCd!="已拖回"){
            			$.ligerDialog.SQalert({content: "只有已拖回的设备才能申请！", SQ_type: "warning"});	
            		}else if(dealStsCd=="优车处置不通过" || (dealStsCd!="未处置" && dealStsCd.indexOf("不通过") < 0)){
            			$.ligerDialog.SQalert({content: "只有未处置/申请不通过的设备才能申请！", SQ_type: "warning"});	
            		}
                	return;
            	}
            	var tcMasterId = selectedRows[0].masterId;//拖车主表ID
    			var tcDetailId = selectedRows[0].id;//拖车明细ID
    			var paySchId = selectedRows[0].paySchId;//支付表ID
    			var paySchNo = selectedRows[0].paySchNo;//支付表号
    			var prjId = selectedRows[0].prjId;//项目表ID
    			var prjPrdDtlId = selectedRows[0].prjPrdDtlId;//项目产品明细表ID
    			var infoId = selectedRows[0].infoId;//拖车实际明细ID
    			var cstId = selectedRows[0].cstId;//客户ID
    			var cstNm = selectedRows[0].cstNm;//客户名称
    			var buOrgCd = selectedRows[0].buOrgCd;//事业部简称
    			var orgName = selectedRows[0].orgName;//事业部名称
    			var backedFlagCd = selectedRows[0].backedFlagCd;//拖回标记(ASS0014)
    			var baseAmt = selectedRows[0].baseAmt;//保底价
    			var actPayAmt = selectedRows[0].actPayAmt;//实际支付金额
    			var businessType = selectedRows[0].businessType;//业务类型
    			var prjTypCd = selectedRows[0].prjTypCd;//项目类型
    			var prjNm = selectedRows[0].prjNm;//项目名称
    			//设置标签名称
    			var title_id = "";
    			var title_info = "";
    			if(json.flag=="1"){
    				title_id = "dealCar";
    				title_info = "处置申请";
    			}else if(json.flag=="2"){
    				title_id = "optimalCar";
    				title_info = "转优车申请";
    			}else if(json.flag=="3"){
    				title_id = "redeemCar";
    				title_info = "赎回申请";
    			}else if(json.flag=="4"){
    				title_id = "logisticsCar";
    				title_info = "转物流申请";
    			}
    			var param = '?tcMasterId='+tcMasterId+'&tcDetailId='+tcDetailId+'&paySchId='+paySchId;
    			param += '&infoId='+infoId+'&cstId='+cstId+'&cstNm='+cstNm+'&orgName='+orgName;
    			param += '&buOrgCd='+buOrgCd+'&backedFlagCd='+backedFlagCd+'&baseAmt='+baseAmt;
    			param += '&actPayAmt='+actPayAmt+'&paySchNo='+paySchNo+'&prjId='+prjId+'&prjPrdDtlId='+prjPrdDtlId;
    			param += '&&prjTypCd='+prjTypCd+'&&prjNm='+prjNm+'&&businessType='+businessType;
    			//回调刷新列表
    			var callback = function () {
    				grid.reload();
    			};
        		Add_navTab(title_id + tcDetailId, title_info, json.url + param, callback);
            }
        });
	}
	//导出信息
	function downloadBtnEvent(){
		var form = new liger.get("searchBar");
		var grid = liger.get("ligergrid1");
		var selectedRows = grid.getSelectedRows();
		var pkIds = new Array();
		for(var i=0;i<selectedRows.length;i++){
			var pkId = "'"+selectedRows[i].paySchId+"'";
			pkIds[i] = pkId;
		}
        var data = form.getData();
        data["pkIds"] = JSON.stringify(pkIds);
        data["eFlag"] = "tcgl";
		var wait_dialog = null;
		$.ajax({
			type: 'get',
			dataType:'json',
			url: '<%=path%>/ass/assTrailCarM/exportAssInfo.do',
			data:data,
			beforeSend:function(){
				wait_dialog=$.ligerDialog.SQalert({content: '正在导出信息...',SQ_type: "waitting"});
			},
			success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					window.open(msg.data);
				}else{
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				}
			} 
		});
	}
	
</script>
</body>
</html>